<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Notification</title>
    <meta name="viewport" content="width=device-width, initial-scale=0.9,  user-scalable=no">
    <link rel="stylesheet" href="//cdnjs.loli.net/ajax/libs/mdui/0.4.1/css/mdui.min.css">
    <script src="//cdnjs.loli.net/ajax/libs/mdui/0.4.1/js/mdui.min.js"></script>
</head>
<style type="text/css">
    table{border-collapse:collapse;margin:0 auto;text-align:center;min-width:100%;}
    table td,table th{color:#2d2d2d;height:30px;}
    table thead th{background-color:#d5d7d3;width:100px;}
    table tr:nth-child(odd){background:#fafcf8;}
    table tr:nth-child(even){background:#fafcf8;}
    link-icon{font-weight: 900;text-align: center;}
</style>
<body class="mdui-theme-accent-pink mdui-theme-primary-teal">
    <header class="mdui-color-theme" style="width: 100%; min-height: 35%;z-index: -1;position: absolute; ">
    </header>
    <div class="mdui-toolbar mdui-color-theme" id="test">

    </div>
    <div class="mdui-container-fluid mdui-m-t-5">
        <div>
            <div class="mdui-col-md-2 mdui-col-sm-0"></div>
            <div class="mdui-col-md-8 mdui-col-sm-12 ">
                <div class="mdui-card mdui-shadow-6 mdui-typo mdui-p-a-4 mdui-m-b-2">
                    <div id = "mktext">
                    </div>
                </div>
                <footer>
                    <div class="mdui-typo mdui-float-right mdui-m-b-3 mdui-m-r-1">
                        <p class="mdui-text-color-theme-300">网站由广药校团委网络中心使用 <a href="https://github.com/Ericwyn/EzeNotify" class="mdui-text-color-theme-300">© EzeNotify</a> 展示</p>
                    </div>
                </footer>
            </div>
            <div class="mdui-col-md-2 mdui-col-sm-0"></div>
        </div>
    </div>

</body>
<script src="js/marked.min.js"></script>
<script>
    function loadConfig() {
        var xhr;
        if(window.XMLHttpRequest){
            xhr = new XMLHttpRequest();
        }else if(window.ActiveXObject){ // 判断是否支持ActiveX控件
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xhr.open('GET', 'config.json', true);
        xhr.send();
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    var data = JSON.parse(xhr.responseText);
                    if(data.title != null){
                        document.title = data.title;
                    }
                    if(data.toolbarTitle !=null ){
                        document.getElementById("test").innerHTML=
                            "<span class=\"mdui-typo-title mdui-m-l-2\" id=\"toolbarTitle\">"+data.toolbarTitle+"</span>\n" +
                            "<div class=\"mdui-toolbar-spacer\"></div>\n" +
                            "<div onclick=\"showMd()\" class=\"mdui-float-right mdui-btn mdui-btn-icon mdui-m-r-2\">\n" +
                            "<i class=\"mdui-icon material-icons link-icon\"><></i>\n" +
                            "</div>";
                    } else {
                        document.getElementById("test").innerHTML=
                            "<span class=\"mdui-typo-title mdui-m-l-2\" id=\"toolbarTitle\">通知</span>\n" +
                            "<div class=\"mdui-toolbar-spacer\"></div>\n" +
                            "<div onclick=\"showMd()\" class=\"mdui-float-right mdui-btn mdui-btn-icon mdui-m-r-2\">\n" +
                            "    <i class=\"mdui-icon material-icons link-icon\"><></i>\n" +
                            "</div>";
                    }
                }
            }
        }
    }
    loadConfig();

    function loadDocument() {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', 'document.md', true);
        xhr.send();
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    document.getElementById("mktext").innerHTML=marked(xhr.responseText);
                } else {
                    console.log(xhr.status);
                    console.log("网络错误");
                }
            }
        }
    }
    loadDocument();
    function showMd() {
        window.location.href = "/document.md"
    }
</script>
</html>
